/*
** xfunc.c for minishell2 in /home/lingla_j/work/tutorat/env
** 
** Made by julien linglain
** Login   <lingla_j@epitech.net>
** 
** Started on  Tue Feb 28 18:08:49 2012 julien linglain
** Last update Thu Apr 12 11:06:38 2012 julien linglain
*/

#include        <sys/types.h>
#include        <stdlib.h>
#include        <stdio.h>
#include        <string.h>
#include        <errno.h>
#include        <sys/wait.h>
#include        <unistd.h>
#include        <dirent.h>
#include	"mysh.h"

void	my_memset(char *buffer, int c, int size)
{
  int	i;

  i = 0;
  while (i < size)
    {
      buffer[i] = (unsigned char)c;
      i = i + 1;
    }
}

void	*xmalloc(unsigned int size)
{
  void	*space;

  space = malloc(size);
  if (space == 0)
    {
      my_puterror("Malloc Error\n");
      exit(EXIT_FAILURE);
    }
  my_memset(space, 0, size);
  return (space);
}

int	xwrite(int d, void *buf, int nbytes)
{
  if (write(d, buf, nbytes) == -1)
    my_puterror("Write Error\n");
  return (0);
}

int	my_tablen(char **av)
{
  int count;

  count = 0;
  while (av[count])
    count = count + 1;
  return (count);
}

int	xread(int fd, char buff[255], int size)
{
  int	nb_read;

  my_memset(buff, 0, size);
  nb_read = read(0, buff, size);
  if (nb_read == 0)
    {
      my_puterror("\n");
      exit(EXIT_FAILURE);
    }
  return (nb_read);
}

